﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;

public partial class Help : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_search_Click(object sender, EventArgs e)
    {
        DVDTableAdapters.DataTable1TableAdapter ta = new DVDTableAdapters.DataTable1TableAdapter();
        DataTable dt= new DataTable();
        dt= ta.GetMovieByCategoryAndTitle(Convert.ToString(ddl_category.SelectedItem.Value), "%"+txt_search.Text+"%");

        GridView1.DataSource = dt;
        
        GridView1.DataBind();

    }

    protected void btn_search_single_Click(object sender, EventArgs e)
    {
        DVDTableAdapters.Movie2TableAdapter ta = new DVDTableAdapters.Movie2TableAdapter();
        DataTable dt = new DataTable();
        dt = ta.GetData("%" + txt_search_single.Text + "%");
        GridView2.DataSource = dt;
        GridView2.DataBind();

    }

    [WebMethod]
    public static List<Movies> GetMovieList(string director)
    {
        //A collection of Module objects is declared as 'modules'
        List<Movies> movies = new List<Movies>();      //The Module class can be found in 
        //the App_Code folder
        DVDTableAdapters.Movie1TableAdapter ta = new DVDTableAdapters.Movie1TableAdapter();
        DataTable dt = ta.GetMovieByDirector(director);
        foreach (DataRow row in dt.Rows)
        {
            int MovieID = Convert.ToInt32(row.ItemArray[0].ToString());      //for each row a new Module object
            string Title = row.ItemArray[1].ToString();    //is instantiated and added to the   
            string Description = row.ItemArray[2].ToString();
            int Length = Convert.ToInt32(row.ItemArray[3].ToString());
            string Director = row.ItemArray[4].ToString();

            movies.Add(new Movies(MovieID, Title, Description, Length, Director));            //collection   
        }
        return movies;
    }
    protected void btn_GoTo_Click(object sender, EventArgs e)
    {
        DVDTableAdapters.Movie1TableAdapter ta = new DVDTableAdapters.Movie1TableAdapter();
        GridView3.DataSource = ta.GetMovieByDirector(ddl_Director.SelectedValue);
        GridView3.DataBind();
    }
}